package DBIx::Class::Timestamper;
use strict;
use base qw(DBIx::Class);
use DateTime;

sub new {
    my ($class, $attrs, @rest) = @_;
    if($class->has_column('created')){
        $attrs->{created} = DateTime->now;
    }
    if($class->has_column('modified')){
        $attrs->{modified} = DateTime->now;
    }
    return $class->next::method( $attrs, @rest );
}

sub update {
    my $self = shift;
    if($self->has_column('modified')){
        $self->modified(DateTime->now);
    }
    $self->next::method(@_);
}

1;
